package operation;

import book.Book;
import book.BookLIst;

import java.util.Scanner;

public class BorrowedBook implements Ioperation{
    public void work(BookLIst books){
        System.out.println("借阅图书");
        System.out.println("请输入你要借阅的图书：");
        Scanner sc = new Scanner(System.in);
        String bookName = sc.nextLine();

        int currentSize = books.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = books.getBook(i);
            if(book.getName().equals(bookName)){
                if(book.isBorrowed()){
                    System.out.println("这本书已经被借出了");
                }else{
                    book.setBorrowed(true);
                    System.out.println(book);
                    System.out.println("借阅成功");
                }
                return;
            }
        }
        System.out.println("没有你找的这本书，无法借阅");
    }
}
